package com.linx.system.controller.system;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.linx.common.idempotent.annotation.RepeatSubmit;
import com.linx.common.log.annotation.Log;
import com.linx.common.web.core.BaseController;
import com.linx.common.mybatis.core.page.PageQuery;
import com.linx.common.core.domain.R;
import com.linx.common.core.validate.AddGroup;
import com.linx.common.core.validate.EditGroup;
import com.linx.common.log.enums.BusinessType;
import com.linx.common.excel.utils.ExcelUtil;
import com.linx.system.domain.vo.AppMenuTypeVo;
import com.linx.system.domain.bo.AppMenuTypeBo;
import com.linx.system.service.IAppMenuTypeService;
import com.linx.common.mybatis.core.page.TableDataInfo;

/**
 * 移动端应用菜单分类
 *
 * @author linx
 * @date 2024-12-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/appMenuType")
public class AppMenuTypeController extends BaseController {

    private final IAppMenuTypeService appMenuTypeService;

    /**
     * 查询移动端应用菜单分类列表
     */
    @SaCheckPermission("system:appMenuType:list")
    @GetMapping("/list")
    public TableDataInfo<AppMenuTypeVo> list(AppMenuTypeBo bo, PageQuery pageQuery) {
        return appMenuTypeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出移动端应用菜单分类列表
     */
    @SaCheckPermission("system:appMenuType:export")
    @Log(title = "移动端应用菜单分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AppMenuTypeBo bo, HttpServletResponse response) {
        List<AppMenuTypeVo> list = appMenuTypeService.queryList(bo);
        ExcelUtil.exportExcel(list, "移动端应用菜单分类", AppMenuTypeVo.class, response);
    }

    /**
     * 获取移动端应用菜单分类详细信息
     *
     * @param appMenuTypeId 主键
     */
    @SaCheckPermission("system:appMenuType:query")
    @GetMapping("/{appMenuTypeId}")
    public R<AppMenuTypeVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long appMenuTypeId) {
        return R.ok(appMenuTypeService.queryById(appMenuTypeId));
    }

    /**
     * 新增移动端应用菜单分类
     */
    @SaCheckPermission("system:appMenuType:add")
    @Log(title = "移动端应用菜单分类", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AppMenuTypeBo bo) {
        return toAjax(appMenuTypeService.insertByBo(bo));
    }

    /**
     * 修改移动端应用菜单分类
     */
    @SaCheckPermission("system:appMenuType:edit")
    @Log(title = "移动端应用菜单分类", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppMenuTypeBo bo) {
        return toAjax(appMenuTypeService.updateByBo(bo));
    }

    /**
     * 删除移动端应用菜单分类
     *
     * @param appMenuTypeIds 主键串
     */
    @SaCheckPermission("system:appMenuType:remove")
    @Log(title = "移动端应用菜单分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{appMenuTypeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] appMenuTypeIds) {
        return toAjax(appMenuTypeService.deleteWithValidByIds(List.of(appMenuTypeIds), true));
    }
}
